package com.dianhun.cn.anno;

import com.sun.org.apache.bcel.internal.generic.RET;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author cyt
 * @create 2020-08-26 13:51
 */
public class MyValidatedImpl implements ConstraintValidator<MyValidated, String> {
    @Override
    public void initialize(MyValidated myValidated) {
        System.out.println("MyValidated - >" + myValidated.message());
    }
    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        /**
         * 得到用户输入的需要检验字段
         */
        String ans = "com.cuiyt.test";
        System.out.println("isValid - > " + value);
        if (ans.equals(value)) {
            ConstraintValidatorContext.ConstraintViolationBuilder test = constraintValidatorContext.buildConstraintViolationWithTemplate("不能含有test");
            return false;
        } else {
            return true;
        }
    }
}
